  var Point = function(x, y) {

    this.x = typeof x === "undefined" ? 0 : x;
    this.y = typeof y === "undefined" ? 0 : y;
  };

  Point.prototype = {

    scalarMult: function(f) {
      this.x *= f;
      this.y *= f;

      return this;
    },

    perpendicular: function() {
      var x = this.x;
      this.x = -this.y;
      this.y = x;

      return this;
    },

    invert: function() {
      this.x = -this.x;
      this.y = -this.y;

      return this;
    },

    length: function() {
      return Math.sqrt(this.x * this.x + this.y * this.y);
    },

    normalize: function() {
      var mod = this.length();
      this.x /= mod;
      this.y /= mod;
      return this;
    },

    angle: function() {
      return this.y / this.x;
    }
  };

  Point.Angle = function(p0, p1) {
    return Math.atan2(p1.x - p0.x, p1.y - p0.y);
  };

  Point.Add = function(p0, p1) {
    return new Point(p0.x + p1.x, p0.y + p1.y);
  };

  Point.Sub = function(p1, p0) {
    return new Point(p1.x - p0.x, p1.y - p0.y);
  };

  Point.Middle = function(p0, p1) {
    return Point.Add(p0, p1).scalarMult(.5);
  };
